package com.neusoft.dibuy.lib.cl;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

public class MyMR {
    public static void main(String[] args) throws Exception {
        // 发票集合
        List<Invoice> invoices = Arrays.asList(
                new Invoice("A01", BigDecimal.valueOf(9.99), BigDecimal.valueOf(1)),
                new Invoice("A02", BigDecimal.valueOf(19.99), BigDecimal.valueOf(1.5)),
                new Invoice("A03", BigDecimal.valueOf(4.99), BigDecimal.valueOf(2))
        );
        BigDecimal reduce = invoices.stream()
                .map(invoice -> invoice.getPrice().multiply(invoice.getQty()))
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println(reduce);
    }
}
class Invoice {

    // 发票号码
    String invoiceNo;
    // 价格
    BigDecimal price;
    // 数量
    BigDecimal qty;

    public String getInvoiceNo() {
        return invoiceNo;
    }

    public void setInvoiceNo(String invoiceNo) {
        this.invoiceNo = invoiceNo;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getQty() {
        return qty;
    }

    public void setQty(BigDecimal qty) {
        this.qty = qty;
    }

    public Invoice(String invoiceNo, BigDecimal price, BigDecimal qty) {

        this.invoiceNo = invoiceNo;
        this.price = price;
        this.qty = qty;
    }
}